package com.wanxi.test;

import java.util.ArrayList;
import java.util.Random;

public class ArrayFor {
    public static void main(String[] args) {
        /**
         * 给定一个返回的字符串，只能在当前字符串里面取字符
         * String str="qwertlzxcvbnm";
         * 在当前字符串随机取4个字符组成字符串
         * 存入到一个字符串的集合：存长度为3个的集合
         */
        ArrayList<String> arrayList = getArrayList(4);

        System.out.println(arrayList);

    }

    private static ArrayList<String> getArrayList(int size) {
        ArrayList<String> arrayList = new ArrayList<>();
        for (int i = 0; i < size; i++) {
            String str = getFourChar();
            System.out.println("当前随机的4个字符为:" + str);
            arrayList.add(str);
        }
        return arrayList;
    }

    private static String getFourChar() {
        String str = "qwertlzxcvbnm";
        String aa = "";
        for (int i = 0; i < 4; i++) {
            Random random = new Random();
            aa += str.charAt(random.nextInt(str.length()));
        }
        return aa;
    }
}
